#include <stdio.h>
#include <sys/socket.h>
#include <netinet/in.h>
#include <arpa/inet.h>
#include <unistd.h>
#include <string.h>
#define SER_PORT 5001
#define IP_ADDR "172.16.2.55"
int main()
{
    // 1.创建套接字
    int sockfd = socket(AF_INET, SOCK_STREAM, 0);
    if (sockfd == -1)
    {
        perror("create socket error");
    }
    struct in_addr ipaddr;
    inet_pton(AF_INET, IP_ADDR, &ipaddr);
    struct sockaddr_in addr;
    addr.sin_addr = ipaddr;
    addr.sin_family = AF_INET;
    addr.sin_port = SER_PORT;
    // 2.绑定地址和端口
    /* int ret = bind(sockfd, (struct sockaddr *)&addr, sizeof(addr));
    if (ret == -1)
    {
        perror("bind error");
    } */

    // 3.发起连接请求
    int ret = connect(sockfd, (struct sockaddr *)&addr, sizeof(addr));
    if (ret == -1)
    {
        perror("connect error");
    }
    // 4.开始发送数据
    write(sockfd, "abcdefg", 7);
    char buf[50];
    read(sockfd, buf, sizeof(buf));
    printf("接收到服务器端返回的消息：%s\n", buf);
    close(sockfd);
}